package com.eight.controller.api;

import com.eight.feign.TbUserFeign;
import com.eight.pojo.TbCarComment;
import com.eight.pojo.TbUser;
import com.eight.service.CarCommentService;
import com.eight.util.JWTTool;
import com.eight.util.TimeUtil;
import com.eight.util.WebUtil;
import com.eight.vo.ComResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/system/api/carComment")
public class CarComment {

    @Autowired private CarCommentService carCommentService;
    @Autowired private TbUserFeign userFeign;

    /**
     * 查询所有车量的评价
     * @return 返回所有评价
     */
    @RequestMapping("/list")
    public ComResult list(){
        return new ComResult(2000,"",carCommentService.list());
    }

    /**
     * 添加新的评价
     * @param tbCarComment 车辆id
     * @return 评价结果
     */
    @PostMapping("/addComment")
    public ComResult addComment(@RequestBody TbCarComment tbCarComment){
        String token = WebUtil.getRequest().getHeader("token");
        TbUser tbUser = userFeign.selectTbUser(token);
        // 谁给车辆评价的
        tbCarComment.setClientId(tbUser.getId());
        tbCarComment.setAddtime(TimeUtil.now(""));
        return new ComResult(2000,"",carCommentService.save(tbCarComment));
    }

}
